<template>
  <el-row class="fs_profile" :gutter="20">
    <el-col :span="8">
      <el-card>
        <template #header>
          <div class="card-header">
            <span>我的信息</span>
          </div>
        </template>
        <el-upload class="avatar-uploader" :action="uploadParams.uploadUrl" :headers="uploadParams.headers"
          :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
          <img v-if="UserInfo.avatar" :src="avatar" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>

        <ul>
          <li class="profile">
            <div class="profile_label">
              <div class="profile_label_text el-icon-s-custom">用户名</div>
            </div>
            <div>{{ UserInfo.username }}</div>
          </li>
          <li class="profile">
            <div class="profile_label">
              <div class="profile_label_text el-icon-user">姓名</div>
            </div>
            <div>{{ UserInfo.nickname }}</div>
          </li>
          <li class="profile">
            <div class="profile_label">
              <div class="profile_label_text el-icon-phone">手机号</div>
            </div>
            <div>{{ UserInfo.phone }}</div>
          </li>
          <li class="profile">
            <div class="profile_label">
              <div class="profile_label_text el-icon-message">邮箱</div>
            </div>
            <div>{{ UserInfo.email }}</div>
          </li>
          <li class="profile">
            <div class="profile_label">
              <div class="profile_label_text el-icon-male">性别</div>
            </div>
            <div>{{ formatSex(UserInfo.sex) }}</div>
          </li>
          <li class="profile">
            <div class="profile_label">
              <div class="profile_label_text el-icon-s-custom el-icon-time">创建时间</div>
            </div>
            <div>{{ formatDate(UserInfo.createTime) }}</div>
          </li>
        </ul>
      </el-card>
    </el-col>

    <el-col :span="16">
      <el-card>
        <template v-slot:header>
          <div>
            <span>个人资料</span>
          </div>
        </template>
        <el-tabs>
          <el-tab-pane label="基本资料">
            <el-form ref="userRef" :model="RestInfo" label-width="80px">
              <el-form-item label="姓名" prop="nickName">
                <el-input v-model="RestInfo.nickname" maxlength="30" />
              </el-form-item>
              <el-form-item label="手机号码" prop="telephone">
                <el-input v-model="RestInfo.phone" maxlength="11" />
              </el-form-item>
              <el-form-item label="邮箱" prop="email">
                <el-input v-model="RestInfo.email" maxlength="50" />
              </el-form-item>
              <!-- 添加性别单选框 -->
              <el-form-item label="性别">
                <el-radio-group v-model="RestInfo.sex">
                  <el-radio v-for="(item, index) in sexDict" :label="item.num" :key="index">{{ item.name }}</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click.native="updateInfo">保存资料</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="修改密码">
            <el-form ref="pwdRef" :model="ResetForm" :rules="rules" label-width="80px">
              <el-form-item label="旧密码" prop="oldPassword">
                <el-input v-model="ResetForm.oldPassword" placeholder="请输入旧密码" type="password" show-password />
              </el-form-item>
              <el-form-item label="新密码" prop="newPassword">
                <el-input v-model="ResetForm.newPassword" placeholder="请输入新密码" type="password" show-password />
              </el-form-item>
              <el-form-item label="确认密码" prop="confirmPassword">
                <el-input v-model="ResetForm.confirmPassword" placeholder="请确认密码" type="password" show-password />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click.native="updatePwd">确认修改</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </el-col>

  </el-row>
</template>
<script src="./user.js"></script>
<style lang="scss">
.fs_profile {
  min-width: 1000px;

  .avatar-uploader {
    text-align: center;
    margin: 30px 0;

    .el-upload {
      border: 1px dashed var(--el-border-color);
      border-radius: 50%;
      cursor: pointer;
      position: relative;
      overflow: hidden;
      transition: var(--el-transition-duration-fast);
      margin: 0 auto;
    }

    .avatar {
      width: 150px;
      height: 150px;
      object-fit: cover;
    }
  }

  .avatar-uploader .el-upload:hover {
    border-color: var(--el-color-primary);
  }

  .el-icon.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;

    text-align: center;
  }

  .profile {
    display: flex;
    justify-content: space-between;
    padding: 15px 5px;
    border-top: 1px solid lightgray;

    .profile_label {
      display: flex;
      color: gray;
      align-items: center;

      .profile_label_icon {
        width: 20px;
        height: 20px;
        margin-right: 4px;
      }

      .profile_label_text {
        flex: none;
      }
    }
  }
}
</style>